package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.RoleMapper;
import com.zhongyu.pojo.Org;
import com.zhongyu.pojo.Role;
import com.zhongyu.service.RoleService;
import com.zhongyu.vo.PageResult;
import com.zhongyu.vo.RoleVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, RoleVo roleVo) {
        LambdaQueryWrapper<Role> wrapper= Wrappers.<Role>lambdaQuery();
        wrapper.like(!StringUtils.isEmpty(roleVo.getRoleName()),Role::getRoleName,roleVo.getRoleName());

        Page page=new Page(pageNo,pageSize);
        List<Role> list=baseMapper.findAll(page,wrapper);
        return new PageResult(list,page.getTotal());
    }

    @Override
    public List<Role> searchById(Integer id) {
        return roleMapper.findById(id);
    }

    @Override
    public List<Role> searchAll() {
        return roleMapper.selectList(null);
    }

    @Override
    public void add(Role role) {
        roleMapper.insert(role);

    }

    @Override
    public void del(Integer id) {
    roleMapper.deleteById(id);
    }

    @Override
    public void update(Role role) {

        roleMapper.updateById(role);

    }

   /* @Override
    public Role selectById(Integer id) {
        return roleMapper.selectById(id);
    }*/
}
